-
Notifications
You must be signed in to change notification settings - Fork 785
Styled Text: add a macro and functions for parsing markdown #10060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Currently getting this error: @ogoffart where should I be registering this? |
This is supposed to be registered in
|
Ohh, right, thanks. Part of the confusion here is that we have both |
Indeed. It is possible to have the item have a different struct name. For example |
4e9e4bc to
b6d3eb8
Compare
a7a2ff7 to
ff8b450
Compare
ogoffart
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the tests, there is not yet test that test any of the generate code.
That should go in tests/cases/element/StyledText, even if its just testing that things compile, and doesn't panic.
(Ideally we shouyld also have rendering rest (eg screenshot tests), but since the screenshot test don't use a renderer that uses parley, this cannot be done now)
There should also be test that tests the error cases.
I also would like to see compile time check of the markdown validity.
| } | ||
| } | ||
|
|
||
| pub fn escape_markdown(text: &str) -> alloc::string::String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can have code with more backticks. That's actually how you escape them.
Which makes me think again that this function cannot really work in the case of code, as it means the "host" markdown will need more ticks.
| TestCase := Window { | ||
| property<styled-text> t1: @markdown("Hello {}", "World"); | ||
| property<styled-text> t2: @markdown("Hello {}", "*World*"); | ||
| property<styled-text> t3: @markdown("Hello *{}*", "World"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In new code, we can avoid using deprecated syntax.
| TestCase := Window { | |
| property<styled-text> t1: @markdown("Hello {}", "World"); | |
| property<styled-text> t2: @markdown("Hello {}", "*World*"); | |
| property<styled-text> t3: @markdown("Hello *{}*", "World"); | |
| } | |
| export component TestCase inherits Window { | |
| out property<styled-text> t1: @markdown("Hello {}", "World"); | |
| out property<styled-text> t2: @markdown("Hello {}", "*World*"); | |
| out property<styled-text> t3: @markdown("Hello *{}*", "World"); | |
| } |
Also this file can be moved to tests/cases/types instead, since it doesn't test the StyledText element, but more the styled-text type.
api/cpp/include/slint_string.h
Outdated
| }; | ||
|
|
||
| /// Styled text that has been parsed and seperated into paragraphs | ||
| class StyledText |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default constructor leaves paragraphs uninitialized.
The refcount is not updated when the StyledText is copied.
The destructor don't delete memory.
We need to add functions cbindgen_private::slint_styled_text_{drop,clone,new}
api/cpp/lib.rs
Outdated
| } | ||
|
|
||
| #[unsafe(no_mangle)] | ||
| pub extern "C" fn slint_parse_markdown(text: &SharedString) -> i_slint_core::api::StyledText { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StyledText will have a destructor so we can't return it.
It should be slint_parse_markdown(text: &SharedString, out: &mut StyledText) or unsafe fn slint_parse_markdown(text: &SharedString, out: *mut StyledText) and we use core::ptr::write into it.
| "Flickable", | ||
| "SimpleText", | ||
| "ComplexText", | ||
| "MarkdownText", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be renamed to StyledTextItem ?
ogoffart
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's merge that for now and do the rest in follow up
No description provided.